import axios, {AxiosResponse} from "axios";
import {BackendPageModel} from "@/models/BackendPageModel";
import OrderModel from "@/models/OrderModel";
import TencentOcrResultModel from "@/models/TencentOcrResultModel";
import {StoreOutRequestModel} from "@/models/StoreOutRequestModel";
import StoreOutModel from "@/models/StoreOutModel";
import {OrderRequestModel} from "@/models/OrderRequestModel";

export function selectOrder(customerNameOrOrderNum = '', pageNum = 1, pageSize = 10,): Promise<BackendPageModel<OrderModel>> {
    return new Promise((resolve, reject) => {
        axios({
            method: 'get',
            url: '/api/ord/page',
            params: {pageNumber: pageNum - 1, pageSize: pageSize, search: customerNameOrOrderNum}
        }).then(value => {
            resolve(value.data);
        }).catch(reason => {
            console.log(reason);
            reject();
        })
    })
}
export function insertOrder(data: OrderRequestModel): Promise<OrderModel> {
    return new Promise((resolve, reject) => {
        axios({method: 'post', url: '/api/ord', data}).then((value: AxiosResponse<OrderModel>) => {
            resolve(value.data);
        }).catch(reason => {
            console.log(reason);
            reject();
        })
    })
}

export function ocrOrder(file: File): Promise<TencentOcrResultModel> {
    return new Promise((resolve, reject) => {
        const form: FormData = new FormData();
        form.set('file', file);
        axios({method: 'post', url: '/api/ord/ocr', data: form}).then((value: AxiosResponse<TencentOcrResultModel>) => {
            resolve(value.data);
        }).catch(reason => {
            console.log(reason);
            reject();
        })
    })
}